package top.gjn998.condition.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import top.gjn998.condition.bean.Dragon;
import top.gjn998.condition.bean.MagicLamp;
import top.gjn998.condition.condition.DragonCondition;

/**
 * @Author guozepeng
 * @Description
 * @Date 2021/11/19
 */
@Configuration
public class MyBeanConfig {
 
    @Bean
    @Conditional(DragonCondition.class)
    public Dragon createDragon() {
        return new Dragon("波伦加",18, "RoadVast");
    }

    /**
     * 如果神龙没有召唤出来，就召唤阿拉丁神灯
     */
    @Bean
    @ConditionalOnMissingBean(Dragon.class)
    public MagicLamp createLamp() {
        return new MagicLamp("阿拉丁", 22, "GJN998");
    }
}